// 定义一步回调
import { sendCodeApi, loginApi } from '@/api/login';
import { setToken } from '@/utils/storage';
import { AppDispatch } from '..';

// 发送验证码
export const sendCodeAction = (mobile: string) => {
  return async () => {
    await sendCodeApi(mobile);
  };
};
// 登录
export const loginAction = (data: { mobile: string; code: string }) => {
  return async (dispatch: AppDispatch) => {
    const res = await loginApi(data);
    // 把token存在store中
    // 做数据持久化
    setToken(res.data);
    dispatch({ type: 'user/saveAuth', payload: res.data });
    // console.log(14, res);
  };
};
//
